//
//  EFAWelContentVC.m
//  efairy
//
//  Created by XiangDongMBP on 2017/9/25.
//  Copyright © 2017年 East. All rights reserved.
//

#import "EFAWelContentVC.h"
#import "GlobalHeader.h"
#import "UIColor+XDHex.h"
#import "EFAModel.h"
#import "EFARootVC.h"
#import "EFALoginNavC.h"

@interface EFAWelContentVC ()
@property (weak, nonatomic) IBOutlet UIImageView *bgImgView;
@property (weak, nonatomic) IBOutlet UIButton *experienceBtn;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;

@end

@implementation EFAWelContentVC

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initNavigationBar];
    [self initSubViews];
}

- (void)initNavigationBar {
    
}

- (void)initSubViews {
    self.bgImgView.image = self.img;
    
    self.experienceBtn.layer.masksToBounds = YES;
    self.experienceBtn.layer.borderWidth = 1;
    self.experienceBtn.layer.cornerRadius = CGRectGetHeight(self.experienceBtn.bounds) / 2.0;
    self.experienceBtn.layer.borderColor = [UIColor xd_colorWithHex:EFAGlobalColorDarkGreen].CGColor;
    [self.experienceBtn addTarget:self action:@selector(experienceBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    self.experienceBtn.hidden = self.btnHidden;
    
    [self.pageControl setCurrentPage:self.pageIndex];
    self.pageControl.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - delegate
#pragma mark - event response
- (void)experienceBtnTapped:(UIButton *)btn {
    if (self.presentingViewController) {    ///< 关于里面，查看欢迎页时使用
        [self dismissViewControllerAnimated:YES completion:nil];
        return;
    }
    
    ///< 引导页的跳转
    if ([EFAModel sharedInstance].isLogin) { ///< 进入登录页面
        [self setupRootVC];
    } else {    ///< 进入主页面
        [self setupLoginVC];
    }
//    //转场动画
//    CATransition *anim = [CATransition animation];
//    anim.type = @"fade";
//    anim.duration = 0.5;
//    [[UIApplication sharedApplication].keyWindow.layer addAnimation:anim forKey:nil];
}

#pragma mark - private methods
- (void)setupRootVC {
//    EFARootVC *rootVC = [[EFARootVC alloc] initWithRefreshUserInfo:YES];
//    [[UIApplication sharedApplication].keyWindow setRootViewController:rootVC];
//    //转场动画
//    CATransition *anim = [CATransition animation];
//    anim.type = @"fade";
//    anim.duration = 0.5;
//    [[UIApplication sharedApplication].keyWindow.layer addAnimation:anim forKey:nil];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:EFAGlobalNotiLoginRootVC object:nil userInfo:nil];
}

- (void)setupLoginVC {
    //UIStoryboard类继承于NSObject，共有三个方法，一个类方法，两个实例方法
    //1）得到一个StoryBoard Object对象：类方法
    UIStoryboard *mainSb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    EFALoginNavC *loginNavC = [mainSb instantiateViewControllerWithIdentifier:@"EFALoginNavC"];
    loginNavC.viewType = 2;
    [[UIApplication sharedApplication].keyWindow setRootViewController:loginNavC];
    //转场动画
    CATransition *anim = [CATransition animation];
    anim.type = @"fade";
    anim.duration = 0.5;
    [[UIApplication sharedApplication].keyWindow.layer addAnimation:anim forKey:nil];
}
#pragma mark - network request
#pragma mark - getters and setters

@end
